<template>
  <el-dialog v-if="load" :close-on-click-modal="false" title="调整" v-model="visible" align-center width="800px" :z-index="2000" @close="handleClose">
    <div class="my-3"><strong>选中数据</strong>: <span class="is--primary">{{ form.pi_ids.length }}</span></div>
    <el-form class="grid grid-cols-2 gap-x-3">
      <el-form-item label="含税折扣">
        <el-input-number v-model="form.preferential_price_tax" controls-position="right" :step="0.01" :precision="10" class="w-full" />
      </el-form-item>
      <el-form-item label="含税售后">
        <el-input-number v-model="form.after_sale_price_tax" controls-position="right" :step="0.01" :precision="10" class="w-full" />
      </el-form-item>
    </el-form>
    <div>若勾选多条调整；则含税折扣、含税售后*勾选的含税入库金额比例分摊</div>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" :loading="loadings.submit" @click="submit">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import api from '../api'
import { ElMessage } from 'element-plus'
const load = ref(false)
const visible = ref(false)
let loadings = reactive({})
const form = ref({})

const emit = defineEmits(['close', 'success'])

// 打开弹窗
const open = async (params) => {
  if (!load.value) {
    load.value = true
    await 1
  }
  loadings = reactive({})
  visible.value = true
  form.value = params
}
// 关闭弹窗
const close = () => {
  visible.value = false
}

const handleClose = () => {
  emit('close')
}
// 提交
const submit = () => {
  loadings.submit = true
  api.adjust(form.value).then(res => {
    emit('success')
    close()
  }).finally(() => {
    loadings.submit = false
  })
}

defineExpose({ open })
</script>